using System;
using System.Configuration;
using System.IO;
using System.Text;
using System.Web.UI;
using facebook;
using System.Web.Configuration;

namespace facebook.web
{
	public class CanvasFBMLMasterPage : MasterPage
	{
      
		private readonly API _api = new API();
	    private bool _requireLogin = false;

	    public string ApiKey { get; set; }

	    public string Secret { get; set; }

        public string suffix
        {
            get { return WebConfigurationManager.AppSettings["Suffix"]; }
        }
        public string callback
        {
            get { return WebConfigurationManager.AppSettings["Callback"]; }
        }
        public string cssVersion
        {
            get { return WebConfigurationManager.AppSettings["CSSVersion"]; }
        }
        public string jsVersion
        {
            get { return WebConfigurationManager.AppSettings["JSVersion"]; }
        }
        
		/// <summary>
		/// Determines whether or not the page being displayed requires that the user be logged into
		/// the application before viewing the page. If this is true, and the user is not logged in,
		/// they will be redirected to the login/allow access page. The default is false.
		/// 
		/// This property must be set before the Page_Init method is called. To set it in a content page
		/// of this master page, set it in that page's Page_PreInit method.
		/// </summary>
        public bool RequireLogin
		{
			get { return _requireLogin; }
            set { _requireLogin = value; }
		}

		public API API
		{
			get { return _api; }
		}

        //public CanvasFBMLMasterPage()
        //{
        //    PreRender += CanvasFBMLMasterPage_PreRender;
        //}

        //internal void CanvasFBMLMasterPage_PreRender(object sender, EventArgs e)
        //{
        //    //var sb = new StringBuilder();
        //    var sw = new StringWriter();
        //    var htmlTW = new HtmlTextWriter(sw);
        //    this.RenderControl(htmlTW);
        //    System.Diagnostics.Debug.WriteLine(sw.ToString());
        //}

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            BasePageHelper.LoadFBMLPage(_api, _requireLogin, Request, Response);
		}

      

	}
}